// map editor for crazy pig

#pragma comment(lib, "SDL.lib")
#pragma comment(lib, "SDLmain.lib")
#pragma comment(lib, "SDL_image.lib")
#pragma comment(lib, "SDL_ttf.lib")

#include <iostream>
#include <fstream>
#include <SDL/SDL.h>
#include "MapIO.h"

using namespace std;

void initSDL();
void outputMap();

int main(int argc, char *argv[])
{
	initSDL();

	MapIO* mapIO = new MapIO();

	mapIO->getInput();
	
	outputMap();

	return 0;
}

void initSDL()
{
	if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
	{
		cerr << "[Error]: " << SDL_GetError() << endl;
		exit(1);
	}

	atexit(SDL_Quit);

}

void outputMap()
{
	string mapfile = "maps\\1.map";
	ofstream outfile(mapfile.data(), ios::out);

	if(!outfile)
	{
		cerr << "Open " << mapfile.data() << "Error!" << endl;
		exit(1);
	}

	for(int i = 0; i < LEVEL_HEIGHT / SIZEY; i++)
	{
		for(int j = 0; j < LEVEL_WIDTH / SIZEX; j++)
		{
			if(Manager :: map[i][j] < 10 & Manager :: map[i][j] >= 0)
				outfile << "0";
			outfile << Manager :: map[i][j] << " ";
		}
		outfile << endl;
	}

	outfile.close();
}